package  
{
	import org.flixel.FlxSprite;
	import org.flixel.FlxG;
	/**
	 * ...
	 * @author ...
	 */
	public class LightCrystal extends FlxSprite
	{
		[Embed(source = '../lib/crystal_lit.png')] protected var crystalPicLit:Class;
		[Embed(source = '../lib/crystal_dark.png')] protected var crystalPicDark:Class;
		[Embed(source = '../lib/BrokenCrystal.png')] protected var picBrokenCrystal:Class;
		[Embed(source = '../lib/CrackedCrystal.png')] protected var picCrackedCrystal:Class;
		[Embed(source = '../lib/FullCrystal.png')] protected var picFullCrystal:Class;
		
		private var isLit:Boolean = true;
		private var lightCounter:Number = 30;
		private const lightLife:Number = 30;
		
		public function LightCrystal(xPos:int, yPos:int, imgClass:Class) 
		{
			super(xPos, yPos, imgClass);
			//this._color = 0x00ffff00;
			health = 7;
			
			this.loadGraphic(picFullCrystal, false, false, 40, 40, false);
		}
		
		override public function update():void
		{
			super.update();
			
			if (lightCounter < 1 && isLit){
				isLit = false;
				//this.color(0x00CCCCCC);
				//this.loadGraphic(crystalPicDark, false, false, 22, 29, false);
			}
			
			if (isLit)
				lightCounter--;
			
			//FlxG.log(lightCounter);
			
			if (health <= 0 )
				this.loadGraphic(picBrokenCrystal, false, false, 40, 40, false);
			
			super.update();
		}
		
		public function lightUp():void
		{
			isLit = true;
			//this.color(0x00ffff00);
			this.loadGraphic(picFullCrystal, false, false, 40, 40, false);
			lightCounter = lightLife;
		}
		
		public function isLitUp():Boolean
		{
			return isLit;
		}
		
		public function TakeDamage(damage:int):void
		{
			this.loadGraphic(picCrackedCrystal, false, false, 40, 40, false);
			health -= damage;
		}
	}

}